package com.geek.framework.study.event.reactive.stream;

import com.geek.framework.study.event.EventListener;
import org.reactivestreams.Subscriber;
import org.reactivestreams.Subscription;

import java.util.EventObject;

/**
 * @Author: ysq
 * @Date: 2021/9/1
 * @Description: 订阅适配器 (实现事件的监听)
 */
public class ListenerSubscriberAdapter implements Subscriber<EventObject>{

  private EventListener listener;

  public ListenerSubscriberAdapter(final EventListener listener) {
    this.listener = listener;
  }

  @Override
  public void onSubscribe(final Subscription subscription) {
    subscription.request(Long.MAX_VALUE);
  }

  @Override
  public void onNext(final EventObject eventObject) {
    listener.onEvent(eventObject);
  }

  @Override
  public void onError(final Throwable throwable) {

  }

  @Override
  public void onComplete() {

  }
}
